﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace SmokinAces
{
  class Menu
  {
    private static int MAX = 20;
    private int menuItemCount;
    private int curMenuItem;
    private string[] menuItems;
    private Vector2[] pos;
    private double[] scale;
    private Color unselected;
    private Color selected;
    private SpriteFont font;

    public Menu(Color unselectedColor, Color selectedColor, SpriteFont sp)
    {
      font = sp;
      menuItems = new string[MAX];
      pos = new Vector2[MAX];
      scale = new double[MAX];
      unselected = unselectedColor;
      selected = selectedColor;
      menuItemCount = 0;
      curMenuItem = 0;
    }

    public void AddMenuItem(string name, Vector2 p)
    {
      if (menuItemCount < MAX)
      {
        menuItems[menuItemCount] = name;
        scale[menuItemCount] = 1.0f;
        pos[menuItemCount] = p;
        menuItemCount++;
      }
    }

    //Edit here for effects  
    public void Draw(SpriteBatch spriteBatch)
    {
      spriteBatch.Begin();
      for (int x = 0; x < menuItemCount; x++)
      {
        if (x == curMenuItem)
        {
          //spriteBatch.DrawString(font, menuItems[x], pos[x], selected);  
          Vector2 p = pos[x];
          p.X -= (float)(22 * scale[x] / 2);
          p.Y -= (float)(22 * scale[x] / 2);
          spriteBatch.DrawString(font, menuItems[x], p, selected, 0.0f, new Vector2(0, 0), (float)scale[x], SpriteEffects.None, 0);
        }
        else
        {
          Vector2 p = pos[x];
          p.X -= (float)(22 * scale[x] / 2);
          p.Y -= (float)(22 * scale[x] / 2);
          spriteBatch.DrawString(font, menuItems[x], p, unselected, 0.0f, new Vector2(0, 0), (float)scale[x], SpriteEffects.None, 0);
        }
      }
      spriteBatch.End();
    }

    public void SelectNext()
    {
      if (curMenuItem < menuItemCount - 1) curMenuItem++;
      else curMenuItem = 0;
    }

    public void SelectPrev()
    {
      if (curMenuItem > 0) curMenuItem--;
      else curMenuItem = menuItemCount - 1;
    }

    public int GetSelectedNum()
    {
      return curMenuItem;
    }

    public string GetSelectedName()
    {
      return menuItems[curMenuItem];
    }

    public void Update(GameTime gameTime)
    {
      for (int x = 0; x < menuItemCount; x++)
      {
        if (x == curMenuItem)
        {
          if (scale[x] < 2.0f)
          {
            scale[x] += 0.04 + 10.0f * gameTime.ElapsedGameTime.Seconds;
          }
        }
        else if (scale[x] > 1.0f && x != curMenuItem)
        {
          scale[x] -= 0.04 + 10.0f * gameTime.ElapsedGameTime.Seconds;
        }
      }
    }
  }
}
